﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Input;
using DC2010;
using DC2010.Objects;

namespace RolePlaying.Events
{
    public class EventsSpellSheet
    {
        public EventsSpellSheet()
        {
            RM.Get("SpellSheet_Switch_12").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS1MouseLeft);
            RM.Get("SpellSheet_Switch_13").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS1MouseLeft);
            RM.Get("SpellSheet_Switch_14").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS1MouseLeft);

            RM.Get("SpellSheet_Switch_21").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS2MouseLeft);
            RM.Get("SpellSheet_Switch_23").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS2MouseLeft);
            RM.Get("SpellSheet_Switch_23").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS2MouseLeft);

            RM.Get("SpellSheet_Switch_31").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS3MouseLeft);
            RM.Get("SpellSheet_Switch_32").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS3MouseLeft);
            RM.Get("SpellSheet_Switch_34").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS3MouseLeft);

            RM.Get("SpellSheet_Switch_41").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS4MouseLeft);
            RM.Get("SpellSheet_Switch_42").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS4MouseLeft);
            RM.Get("SpellSheet_Switch_43").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSS4MouseLeft);

            RM.Get("SpellSheet_BACK").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnMouseLeft);

            RM.Get("SpellSheet_LO").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);
            RM.Get("SpellSheet_UM").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);
            RM.Get("SpellSheet_ON").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);
            RM.Get("SpellSheet_EE").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);
            RM.Get("SpellSheet_PAL").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);
            RM.Get("SpellSheet_MON").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnSpellMouseLeft);

            RM.Get("SpellSheet_CAST").OnMouseLeft += new ActiveRectangle.mouseStateDelegate(RM_OnCastSpellMouseLeft);
 
        }

        void RM_OnCastSpellMouseLeft(MouseState state, ActiveRectangle ar)
        {
           // Root.I.SpellSystem.DetermineSpell();
        }


        void RM_OnSpellMouseLeft(MouseState state, ActiveRectangle ar)
        {
            //if (Root.I.GameSystem.ActiveCaster != 0) // just check
            //{
            //    int selectedMember = Root.I.GameSystem.ActiveCaster;
            //    Creature c = Root.I.GameSystem.Party.Info.MembersBrowsable[selectedMember];

            //    if (c.Info.SpellSheetSpell.Length <= 4)
            //    {

            //        if (ar.Name == "SpellSheet_LO")
            //        {
            //            if (c.Info.SpellSheetSpell.Length < 5)
            //            {
            //                string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][0].ToString();
            //                Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //                if (c.PumpMana(r.Info.Difficulty_Lo))
            //                    c.Info.SpellSheetSpell += RuneCode;
            //            }
            //        }
            //        if (ar.Name == "SpellSheet_UM")
            //        {
            //            string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][1].ToString();
            //            Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //            if (c.PumpMana(r.Info.Difficulty_Um))
            //                c.Info.SpellSheetSpell += RuneCode;
            //        }
            //        if (ar.Name == "SpellSheet_ON")
            //        {
            //            string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][2].ToString();
            //            Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //            if (c.PumpMana(r.Info.Difficulty_On))
            //                c.Info.SpellSheetSpell += RuneCode;
            //        }
            //        if (ar.Name == "SpellSheet_EE")
            //        {
            //            string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][3].ToString();
            //            Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //            if (c.PumpMana(r.Info.Difficulty_Ee))
            //                c.Info.SpellSheetSpell += RuneCode;
            //        }
            //        if (ar.Name == "SpellSheet_PAL")
            //        {
            //            string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][4].ToString();
            //            Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //            if (c.PumpMana(r.Info.Difficulty_Pal))
            //                c.Info.SpellSheetSpell += RuneCode;
            //        }
            //        if (ar.Name == "SpellSheet_MON")
            //        {
            //            string RuneCode = Root.I.SpellSystem.SpellBoard[c.Info.SpellSheetSpell.Length + 1][5].ToString();
            //            Rune r = Root.I.RuneSystem.GetRuneByChar(RuneCode);
            //            if (c.PumpMana(r.Info.Difficulty_Mon))
            //                c.Info.SpellSheetSpell += RuneCode;
            //        }
            //    }
            //}

        }

        void RM_OnMouseLeft(MouseState state, ActiveRectangle ar)
        {
            //if (Root.I.GameSystem.ActiveCaster != 0) // just check
            //{
            //    int selectedMember = Root.I.GameSystem.ActiveCaster;
            //    CreatureData c = Root.I.GameSystem.Party.Info.MembersBrowsable[selectedMember];

            //    if (c.Info.SpellSheetSpell.Length != 0)
            //    {
            //        c.Info.SpellSheetSpell = c.Info.SpellSheetSpell.Substring(0, c.Info.SpellSheetSpell.Length - 1);
            //    }
            //}
        }

        void RM_OnSS1MouseLeft(MouseState state, ActiveRectangle ar)
        {
            if (Root.I.GameSystem.ActiveCaster == 1) // just check
            {
                int newActiveCaster = Int32.Parse(ar.Name[ar.Name.Length - 1].ToString());
                Root.I.GameSystem.ActiveCaster = newActiveCaster;
            }
        }

        void RM_OnSS2MouseLeft(MouseState state, ActiveRectangle ar)
        {
            if (Root.I.GameSystem.ActiveCaster == 2) // just check
            {
                int newActiveCaster = Int32.Parse(ar.Name[ar.Name.Length - 1].ToString());
                Root.I.GameSystem.ActiveCaster = newActiveCaster;
            }
        }

        void RM_OnSS3MouseLeft(MouseState state, ActiveRectangle ar)
        {
            if (Root.I.GameSystem.ActiveCaster == 3) // just check
            {
                int newActiveCaster = Int32.Parse(ar.Name[ar.Name.Length - 1].ToString());
                Root.I.GameSystem.ActiveCaster = newActiveCaster;
            }
        }

        void RM_OnSS4MouseLeft(MouseState state, ActiveRectangle ar)
        {
            if (Root.I.GameSystem.ActiveCaster == 4) // just check
            {
                int newActiveCaster = Int32.Parse(ar.Name[ar.Name.Length - 1].ToString());
                Root.I.GameSystem.ActiveCaster = newActiveCaster;
            }
        }

    }
}
